unit Video; { Added to Image to perform video operations and time-laps tasks-still a rough version but works} interface uses Camera, Sound, file1, Serial, QuickDraw, Palettes, PrintTraps, globals, Utilities, Graphics, Filters, Analysis; procedure InitVideo; procedure DoVcrMenuEvent (MenuItem: integer); procedure DoFramesMenuevent (Menuitem: integer); procedure DoTLMenuevent (Menuitem: integer); implementation type InString = packed array[1..60] of CHAR; Video = (Vcr, Card); var SerErr, RefNum, RefNumIN: integer; flags: Sershk; count: longint; outStrV, TheStr: str255; InStr: InString; SaveErr: OSerr; NumOfFrames: LongInt; {----------->Init Video Menus<----------} procedure InitVideo; begin UserMenuH := GetMenu(VcrMenu); InsertMenu(UserMenuH, 0); UserMenuH := GetMenu(TLMenu); InsertMenu(UserMenuH, -1); UserMenuH := GetMenu(FramesMenu); InsertMenu(UserMenuH, -1); {*To Make active-change "CaseMenu.." in Image.p} DrawMenuBar; end; {==============Routines for the Serial Port================} {-------------------Init Serial Port-----------------------} procedure initserial; begin SerErr := OpenDriver('.Aout', RefNum); if SerErr <> 0 then writeln('OpenDriver error number ', SerErr); SerErr := serReset(Refnum, baud2400 + data7 + oddParity + stop10); if SerErr <> 0 then writeln('Reset error number ', SerErr); SerErr := OpenDriver('.AIn', RefNumIN); if SerErr <> 0 then writeln('OpenDriver error number ', SerErr); flags.fcts := 0; if SerErr <> 0 then writeln('Hand-shake error ', SerErr); end; {------------------Close Serial Port-------------} procedure CloseSerDriver; begin SerErr := CloseDriver(RefNum); if SerErr <> 0 then writeln('CloseDriver (Out) error number ', SerErr); SerErr := CloseDriver(RefNumIn); if SerErr <> 0 then writeln('CloseDriver (Out) error number ', SerErr); end; {--------------------SEND to Video----------------------} procedure SendVcr (sendStr: Str255); begin {SerErr := KillIO(-7);} if SerErr <> 0 then writeln('KillIO error number: ', SerErr); outStrV := concat(chr($02), SendStr, chr($03)); count := length(outStrV) + 2; SerErr := Fswrite(refNum, count, ptr(@outStrV)); if SerErr <> 0 then writeln('Fswrite error number ', SerErr); end; {--------------------GET From Serial Port (VCR)-----------------------} procedure GetVcr; begin SerErr := SerGetBuf(RefNumIN, count); if SerErr <> 0 then writeln('SerGetBuf error number ', SerErr); SerErr := Fsread(RefNumIN, count, ptr(@Instr)); if SerErr <> 0 then writeln('Fsread error number ', SerErr); end; {==================>TimeLaps<=====================} {The main routine contains its own resources and dialogue handling} procedure TimeLaps (Vcr_Or_Card: Video); const SLEEP = 60; BASE_RES_ID = 402; VCR_RES_ID = 131; SAVE_BUTTON = 1; CANCEL_BUTTON = 2; SOUND_ON_BOX = 3; SECS_RADIO = 9; MINS_RADIO = 10; DEFAULT_SECS_ID = 401; DEFAULT_MINS_ID = 402; ON = 1; OFF = 0; SECOND_PER_MINUTE = 60; TOP = 15; LEFT = 2; NUM_GRABS = 5; INTERVAL = 7; DURATION = 14; type Settings = record Interval, NumFrames, sound, duration: integer; end; var gSettingsDialogue: DialogPtr; FirstTime, NumToGrab, TheDuration, TheInterval, GetTime, StartTime, SaveTime: LongInt; SavedSettings: Settings; n, i: integer; FrameNum, Aname, TheName, thetime, MyTimeString: str255; Counter: integer; gdone, gcounting, QQ: boolean; gTheEvent: EventRecord; Textpoint: point; seconds_or_minutes: (seconds, minutes); dummyStr: str255; itemType: integer; itemRect: Rect; itemHandle, ShutterSound: Handle; TheReply: SFreply; {} procedure HandleEvent; forward; {------>CountDown<------------} procedure countDown (numSecs: longint); var myTime, oldTime, difTime, Counter: Longint; MyTimeString, Dummy1, Dummy2: Str255; CountWindow: WindowPtr; begin CountWindow := getNewWindow(BASE_RES_ID - 2, nil, WINDOWPTR(-1)); SetPort(CountWindow); ShowWindow(CountWindow); GetDateTime(myTime); if seconds_or_minutes = minutes then numSecs := numSecs * SECOND_PER_MINUTE; Counter := NumSecs; oldTime := myTime; gCounting := TRUE; while (Counter > 0) and gCounting and not (spacebardown and button) do begin HandleEvent; if gCounting then begin MoveTo(LEFT, TOP); GetDateTime(myTime); IUTimeString(myTime, True, MyTimeString); if myTime <> oldTime then begin Counter := Counter - 1; oldTime := myTime; EraseRect(CountWindow^.PortRect); DrawString(MyTimeString); MoveTo(LEFT, TOP + 15); NumToString(MyTime - StartTime, Dummy2); DrawString(concat('Time From Start:', Dummy2, ' sec')); MoveTo(LEFT, TOP + 30); NumTOString(NumToGrab, Dummy1); NumTOString(i, Dummy2); DrawString(concat('Frames:', Dummy2, '/', Dummy1)); MoveTo(LEFT, TOP + 45); NumToString(TheInterval, Dummy1); if seconds_or_minutes = minutes then Dummy2 := ' min' else Dummy2 := ' sec'; DrawString(concat('Time Interval:', Dummy1, Dummy2)); end; HandleEvent; end; end; if gCounting then gCounting := FALSE; DisposeWindow(CountWindow); end; {---------------> RestoreSetting <--------------} procedure RestoreSettings; var itemType: integer; itemRect: Rect; itemHandle: Handle; begin GetDitem(gSettingsDialogue, SOUND_ON_BOX, itemType, itemhandle, itemRect); SetCtlValue(ControlHandle(itemHandle), SavedSettings.sound); GetDitem(gSettingsDialogue, NUM_GRABS, itemType, itemhandle, itemRect); SetCtlValue(ControlHandle(itemHandle), SavedSettings.NumFrames); GetDitem(gSettingsDialogue, INTERVAL, itemType, itemhandle, itemRect); SetCtlValue(ControlHandle(itemHandle), SavedSettings.Interval); if VCR_OR_CARD = VCR then begin GetDitem(gSettingsDialogue, DURATION, itemType, itemhandle, itemRect); SetCtlValue(ControlHandle(itemHandle), SavedSettings.Duration); end; end; {----------------->Play Sound <---------------} procedure PlaySound; var itemtype: integer; itemREct: rect; itemHandle: Handle; dummy: OSerr; fileMenu: MenuHandle; APointer: Ptr; SndErr: OSErr; begin GetDItem(gSettingsDialogue, SOUND_ON_BOX, itemType, itemHandle, itemRect); if GetCtlValue(controlHAndle(itemHAndle)) = on then ShutterSound := GetResource('snd ', 100) else ShutterSound := nil; SndErr := SndPlay(nil, ShutterSound, false); end; {------------->SAVE SETTING------------} procedure SaveSettings; var itemType: integer; itemRect: Rect; itemHandle: Handle; begin GetDitem(gSettingsDialogue, SOUND_ON_BOX, itemType, itemhandle, itemRect); SavedSettings.Sound := GetCtlValue(ControlHandle(itemHandle)); GetDitem(gSettingsDialogue, NUM_GRABS, itemType, itemhandle, itemRect); SavedSettings.NumFrames := GetCtlValue(ControlHandle(itemHandle)); GetDitem(gSettingsDialogue, INTERVAL, itemType, itemhandle, itemRect); SavedSettings.Interval := GetCtlValue(ControlHandle(itemHandle)); if VCR_OR_CARD = VCR then begin GetDitem(gSettingsDialogue, DURATION, itemType, itemhandle, itemRect); SavedSettings.Duration := GetCtlValue(ControlHandle(itemHandle)); end; end; {---------------> HandleDialog <--------------} procedure HandleDialog; var DialogDone: boolean; ItemHit, ItemType: integer; itemRect: Rect; itemHandle: Handle; begin if VCR_OR_CARD = VCR then gSettingsDialogue := GetNewDialog(VCR_RES_ID, nil, windowptr(-1)) else gSettingsDialogue := GetNewDialog(Base_res_id, nil, windowptr(-1)); showwindow(gSettingsDialogue); SaveSettings; dialogDone := FALSE; while dialogDone = FALSE do begin ModalDialog(nil, itemHit); case itemHit of SAVE_BUTTON: begin Hidewindow(gSettingsDialogue); saveSettings; dialogDone := TRUE; end; CANCEL_BUTTON: begin Hidewindow(gSettingsDialogue); RestoreSettings; dialogDone := TRUE; end; SOUND_ON_BOX: begin GetDItem(gSettingsDialogue, SOUND_ON_BOX, ItemType, ItemHandle, ItemRect); if GetCtlValue(ControlHandle(itemHandle)) = on then begin SetCtlValue(ControlHandle(itemHandle), off); end else SetCtlValue(ControlHandle(itemHandle), on) end; SECS_RADIO: begin seconds_or_minutes := Seconds; GetDItem(gSettingsDialogue, MINS_RADIO, ItemType, ItemHandle, ItemRect); SetCtlValue(ControlHandle(itemHandle), off); GetDItem(gSettingsDialogue, SECS_RADIO, ItemType, ItemHandle, ItemRect); SetCtlValue(ControlHandle(itemHandle), on); GetDItem(gSettingsDialogue, NUM_GRABS, ItemType, ItemHandle, ItemRect); GetDItem(gSettingsDialogue, INTERVAL, ItemType, ItemHandle, ItemRect); end; MINS_RADIO: begin seconds_or_minutes := Minutes; GetDItem(gSettingsDialogue, SECS_RADIO, ItemType, ItemHandle, ItemRect); SetCtlValue(ControlHandle(itemHandle), off); GetDItem(gSettingsDialogue, MINS_RADIO, ItemType, ItemHandle, ItemRect); SetCtlValue(ControlHandle(itemHandle), on); GetDItem(gSettingsDialogue, NUM_GRABS, ItemType, ItemHandle, ItemRect); GetDItem(gSettingsDialogue, INTERVAL, ItemType, ItemHandle, ItemRect); end; end; end; end; {------------>HandleMouseDown<------------} procedure HandleMousedown; var whichwindow: windowptr; thePart: integer; menuchoice, windSize: longint; begin thepart := findwindow(gTheEvent.where, whichwindow); case thePart of inSysWindow: SystemClick(gtheEvent, WhichWindow); { other applications} inGoAway: {quit} gDone := true; end; end; {------------->Handle Event<------------------} procedure HandleEvent; var thechar: char; dummy: boolean; begin dummy := WaitNextEvent(everyEvent, gTheEvent, SLEEP, nil); case gTheEvent.what of mousedown: handlemousedown; keyDown, AutoKey: begin theChar := Chr(BitAnd(GTheEvent.Message, charCodeMask)); if (BitAnd(gTheEvent.modifiers, cmdKey) <> 0) then gdone := True; if spacebardown and button then begin sysbeep(1); gDone := true; end; end; end; end; {------------>Main<----------------} {>The Time Laps code. It asks whether the TL is via Grabber or VCR and response accordingly} begin gDone := false; HandleDialog; GetDItem(gSettingsDialogue, NUM_GRABS, itemtype, itemHandle, itemrect); GetIText(itemHandle, dummyStr); StringToNum(dummyStr, NumToGrab); GetDItem(gSettingsDialogue, INTERVAL, itemtype, itemHandle, itemrect); GetIText(itemHandle, dummyStr); StringToNum(dummyStr, TheInterval); QQ := False; StartDigitizing; StopDigitizing; CaptureandDisplayFrame; SaveAsTL(QQ, Aname, RefNum); if QQ then Exit(TimeLaps); i := 0; GetDateTime(StartTime); while not gDone do begin i := i + 1; if (i = NumToGrab) then gDone := true; CountDown(TheInterval); if spacebardown and button then begin exit(timelaps); sysbeep(1); end; numtostring(i, FrameNum); TheName := concat(aName, FrameNum); StartDigitizing; StopDigitizing; CaptureAndDisplayFrame; Textpoint.h := 25; Textpoint.v := 20; GetDateTime(SaveTime); IUTimeString(SaveTime, True, MyTimeString); DrawTextString(MyTimeString, Textpoint, TextJust); SaveTime := SaveTime - StartTime; Textpoint.h := 25; Textpoint.v := 35; NumToString(SaveTime, MyTimeString); DrawTextString(concat('FrameTime:', MyTimeString, 'sec'), Textpoint, TextJust); SaveAsTiff(TheName, DefaultRefNum, 300, 300, false); PlaySound; DoClose; end; disposehandle(ShutterSound); end; {-----} procedure DoFramesMenuevent (Menuitem: integer); begin case menuitem of 1: SENDVCR('OSF:1'); 2: SENDVCR('OSF:2'); 3: SENDVCR('OSF:4'); 4: SENDVCR('OSF:6'); 5: SENDVCR('OSF:8'); 6: SENDVCR('OSR:8'); 7: SENDVCR('OSR:4'); 8: SENDVCR('OSR:2'); 9: SENDVCR('OSR:1'); end; end; procedure DoTLMenuevent (Menuitem: integer); var Vcr_Or_Card: Video; begin case menuitem of 1: Vcr_Or_Card := Card; 2: Vcr_Or_Card := Vcr; end; TimeLaps(Vcr_Or_Card); end; {>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>DOVCR<<<<<<<<<<<<<<<<<<<<<<<<<} procedure DoVcrMenuEvent (MenuItem: integer); var TLMenuItem: integer; framesMenuH, TLMenuH: MenuHandle; junk: str255; begin initserial; case MenuItem of 1: SENDVCR('OPL'); {Play} 2: SENDVCR('ORW');{Rewind} 3: SENDVCR('OFF'); 4: SENDVCR('OSP'); 5: SENDVCR('OPA'); 6: begin end; 7: SENDVCR('ODN'); 8: begin end; 9: SENDVCR('CRT'); end; end; end. if VCR_OR_CARD = VCR then begin GetDitem(gSettingsDialogue, DURATION, itemType, itemhandle, itemRect); GetIText(itemHandle, dummyStr); StringToNum(dummyStr, TheDuration); initserial; i := 0; while not gDone do begin i := i + 1; if (i = NumToGrab) then gDone := true; if spacebardown and button then begin SendVcr('OSP'); exit(timelaps); sysbeep(1); end; SendVcr('ORC'); countDown(TheDuration); SendVcr('OSP'); CountDown(TheInterval); PlaySound; end end else begin